﻿using ConfExpert.Forms.Araclar;
using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraNavBar;

using DevTeamIT;
using System.Data;
using System.Windows.Forms;


namespace ConfExpert.Forms.DockingControls
{
    public class CustomerBasedOperations : DockingControlBase
    {
        public CustomerBasedOperations(NavBarControl navBar, GridLookUpEdit gleCustomer)
        {
            NavigationBar = navBar;
            Lookup = gleCustomer;

            NavigationBar.Groups.Clear();


            /*
             * ÖNEMLİ: bu şekilde kullanıldığında filtre programdaki tüm customer lookup'larını etkiliyor!
             * 
            string filter = "CustomerId in (42,68,22) ";
            DataView dv = RepositoryManager.dsi.V_Customer.DefaultView;
            dv.RowFilter = filter;
            */
            XForm x = new XForm();
            //DataTable dt = Session.DataManager.ExecuteDataTable("GetCustomersForBaseForm");
            //RepositoryItemGridLookUpEdit riCustomer = x.GetCustomGLE(dt, "Name", "CustomerId");     //OA.2

            DataTable dt = Session.DataManager.ExecuteDataTable("GetMyCustomers2", Session.CurrentUser.UserId);
            dt.Columns.RemoveAt(2); //cari
            RepositoryItemGridLookUpEdit riCustomers = x.GetCustomGLE(dt, "Name", "CustomerId");
            Lookup.Properties.Assign(riCustomers);

            //Lookup.Properties.PopupFilterMode = PopupFilterMode.Contains;
            //Lookup.Properties.View.Columns["Name"].OptionsFilter.AutoFilterCondition = AppSession.Settings.AutoFilterCondition == "Contains" ? AutoFilterCondition.Contains : AutoFilterCondition.Like;
            //Lookup.Properties.Assign(x.RI(Rp.V_Customer));
            //Lookup.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            //gleCustomer.EditValue = RepositoryManager.dsi.V_Customer.Rows[0]["CustomerId"];

            gleCustomer.EditValueChanged += delegate { Refresh(); };

            if (Session.gleCustomer > 0)
                Lookup.EditValue = Session.gleCustomer;
        }

        public void Refresh()
        {
            NavBarGroup group;
            NavigationBar.Groups.Clear();

            if (Lookup.EditValue != null)
            {
                int CustomerId = (int)Lookup.EditValue;
                Session.gleCustomer = CustomerId;

               
                  //group = AddGroup("Yükleme Bilgi Formu");
                //AddMenuItem(group, "Yeni Oluştur", typeof(YuklemeFormu), CustomerId);
                //AddMenuItem(group, "Liste", typeof(YuklemeFormlari), CustomerId);

            }
        }
 

        
    }
}